package cn.edu.njpi;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/**
 * @author 朱宗辉
 * @version V1.0
 * @Package cn.edu.njpi
 * @date 2022/5/11 9:06 PM
 */
public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Group root = new Group();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("javafx");
        stage.setWidth(800);
        stage.setHeight(800);
        TextField text = new TextField();
        text.setText("这个是文本");
        text.setLayoutX(100);
        text.setLayoutY(100);
        text.setPrefHeight(100);
        text.setPrefWidth(100);
        text.setFont(Font.font(15));
        Tooltip tip = new Tooltip();
        tip.setText("这是提示");
        tip.setFont(Font.font(40));
        text.setTooltip(tip);
        text.setPromptText("请输入文件");
        text.setFocusTraversable(false);
        text.textProperty().addListener((observableValue, s, t1) -> {
            if (t1.length() > 7) {
                text.setText(s);
            }
        });
        text.selectedTextProperty().addListener((observableValue, s, t1) -> System.out.println(t1));
        PasswordField passwordField = new PasswordField();
        passwordField.setLayoutX(300);
        passwordField.setLayoutY(300);
        passwordField.setPrefHeight(100);
        passwordField.setPrefWidth(100);
        passwordField.textProperty().addListener((observableValue, s, t1) -> System.out.println("当前密码为: " + t1));
        Label label = new Label();
        label.setText("我是标签");
        label.setLayoutY(100);
        root.getChildren().add(label);
        root.getChildren().add(passwordField);
        root.getChildren().add(text);
        stage.show();
    }
}
